<template>
  <page-header-wrapper :title="false">
    <a-card
      :body-style="{ padding: '24px 32px' }"
      :bordered="false"
      :tabList="tabList"
      :activeTabKey="activeTabKey"
      @tabChange="
        (key) => {
          this.activeTabKey = key
        }
      "
    >
      <div class="table-page-search-wrapper">
        <a-form layout="inline">
          <a-row :gutter="48">
            <a-col :md="6" :sm="24">
              <a-form-item label="退库日期">
                <a-range-picker v-model="value4" />
              </a-form-item>
            </a-col>
            <a-col :md="6" :sm="24">
              <a-form-item label="筛选">
                <a-input v-model="value" placeholder="请输入" />
              </a-form-item>
            </a-col>
            <a-col :md="(!advanced && 8) || 24" :sm="24">
              <span
                class="table-page-search-submitButtons"
                :style="(advanced && { float: 'right', overflow: 'hidden' }) || {}"
              >
                <a-button type="primary" :loading="loading" @click="handleSearch()">查询</a-button>
                <a-button style="margin-left: 8px" @click="() => (queryParam = {})">重置</a-button>
              </span>
            </a-col>
          </a-row>
        </a-form>
      </div>
      <a-table
        ref="table"
        size="default"
        rowKey="key"
        :columns="columns"
        :data-source="loadData"
        v-if="this.activeTabKey == '1'"
      >
        <span slot="serial" slot-scope="text, record, index">
          {{ index + 1 }}
        </span>
        <span slot="status" slot-scope="text, record">
          <template>
            <a-tag color="#82af6f" v-if="record?.status == 1">已审核</a-tag>
            <a-tag color="#D15B47" v-else>待审核</a-tag>
          </template>
        </span>
        <span slot="action" slot-scope="text, record">
          <template> <a-tag color="#428bca" @click="handleDetail(record)">详情</a-tag> </template>
        </span>
      </a-table>
      <a-table
        ref="table"
        size="default"
        rowKey="key"
        :columns="columns2"
        :data-source="loadData"
        v-if="this.activeTabKey == '2'"
      >
        <span slot="serial" slot-scope="text, record, index">
          {{ index + 1 }}
        </span>
        <span slot="status" slot-scope="text, record">
          <template>
            <a-tag color="#82af6f" v-if="record?.status == 1">已审核</a-tag>
            <a-tag color="#D15B47" v-else>待审核</a-tag>
          </template>
        </span>
        <span slot="action" slot-scope="text, record">
          <template> <a-tag color="#428bca" @click="handleDetail(record)">详情</a-tag> </template>
        </span>
      </a-table>
      <a-table
        ref="table"
        size="default"
        rowKey="key"
        :columns="columns3"
        :data-source="loadData"
        v-if="this.activeTabKey == '3'"
      >
        <span slot="serial" slot-scope="text, record, index">
          {{ index + 1 }}
        </span>
        <span slot="status" slot-scope="text, record">
          <template>
            <a-tag color="#82af6f" v-if="record?.status == 1">已审核</a-tag>
            <a-tag color="#D15B47" v-else>待审核</a-tag>
          </template>
        </span>
        <span slot="action" slot-scope="text, record">
          <template> <a-tag color="#428bca" @click="handleDetail(record)">详情</a-tag> </template>
        </span>
      </a-table>
    </a-card>
  </page-header-wrapper>
</template>

<script>
export default {
  name: 'ShopReportDetails',
  data() {
    return {
      mdl: null,
      visible: false,
      value: '',
      value4: '',
      tabList: [
        { key: '1', tab: '员工统计' },
        { key: '2', tab: '商品名统计' },
        { key: '3', tab: '供应商统计' },
      ],

      activeTabKey: '1',
      confirmLoading: false,
      // 高级搜索 展开/关闭
      advanced: false,
      // 查询参数
      queryParam: {},
      // 表头
      columns: [
        {
          title: '员工名',
          dataIndex: 'empName',
        },
        {
          title: '销量',
          dataIndex: 'salesVolume',
        },
        {
          title: '销售额',
          dataIndex: 'salesAmount',
        },
        {
          title: '成本',
          dataIndex: 'commCost',
        },
        {
          title: '礼品成本',
          dataIndex: 'giftCommCost',
        },
        {
          title: '销售毛利(元)',
          dataIndex: 'salesGrossProfit',
        },
        {
          title: '单机毛利(元)',
          dataIndex: 'unitGrossProfit',
        },
        {
          title: '毛利率',
          dataIndex: 'grossMargin',
        },
        {
          title: '退货',
          dataIndex: 'returnsAmount',
        },
        {
          title: '退货折损毛利',
          dataIndex: 'reDisGrossProfit',
        },
        {
          title: '总毛利',
          dataIndex: 'grossProfitTotal',
        },
        {
          title: '操作',
          dataIndex: 'action',
          width: '180px',
          scopedSlots: { customRender: 'action' },
        },
      ],
      columns2: [
        {
          title: '商品名',
          dataIndex: 'goodsName',
        },
        {
          title: '销量',
          dataIndex: 'salesVolume',
        },
        {
          title: '销售额',
          dataIndex: 'salesAmount',
        },
        {
          title: '成本',
          dataIndex: 'commCost',
        },
        {
          title: '礼品成本',
          dataIndex: 'giftCommCost',
        },
        {
          title: '销售毛利',
          dataIndex: 'salesGrossProfit',
        },
        {
          title: '单机毛利',
          dataIndex: 'unitGrossProfit',
        },
        {
          title: '毛利率',
          dataIndex: 'grossMargin',
        },
        {
          title: '退货',
          dataIndex: 'returnsAmount',
        },
        {
          title: '退货折损毛利',
          dataIndex: 'reDisGrossProfit',
        },
        {
          title: '总毛利',
          dataIndex: 'grossProfitTotal',
        },
        {
          title: '操作',
          dataIndex: 'action',
          width: '180px',
          scopedSlots: { customRender: 'action' },
        },
      ],
      columns3: [
        {
          title: '供应商',
          dataIndex: 'supplyName',
        },
        {
          title: '销量',
          dataIndex: 'salesVolume',
        },
        {
          title: '销售额',
          dataIndex: 'salesAmount',
        },
        {
          title: '成本',
          dataIndex: 'commCost',
        },
        {
          title: '礼品成本',
          dataIndex: 'giftCommCost',
        },
        {
          title: '销售毛利',
          dataIndex: 'salesGrossProfit',
        },
        {
          title: '单机毛利',
          dataIndex: 'unitGrossProfit',
        },
        {
          title: '毛利率',
          dataIndex: 'grossProfitTotal',
        },
        {
          title: '操作',
          dataIndex: 'action',
          width: '180px',
          scopedSlots: { customRender: 'action' },
        },
      ],
      loading: false,
      // 加载数据方法 必须为 Promise 对象
      loadData: [
        {
          empId: '1',
          empName: '王升',
          supplyName: '王升',
          goodsName: '王升',
          salesVolume: '100',
          salesAmount: '10000',
          commCost: '100',
          giftCommCost: '10',
          salesGrossProfit: '10',
          unitGrossProfit: '10',
          grossMargin: '5%',
          returnsAmount: '12',
          reDisGrossProfit: '120',
          grossProfitTotal: '1000'
        },
      ],
    }
  },
  methods: {
    handleSearch() {
      this.loading = true
      setTimeout(() => {
        this.loading = false
      }, 1000)
    },
    handleDetail(record) {
      this.$router.push({ path: `/report/shopReport/goodsDetail/${record?.id}` })
    },
  },
}
</script>